home *** CD-ROM | disk | FTP | other *** search
- /*
- File: HalftonePrimitive.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains routines for setting the
- current halftone screens of the PostScript
- device.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1992-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #include "GXToPSBuildConfig.h"
- #include <GXGraphics.h>
- #include "GXGraphicsPriv.h"
- #include <GXEnvironment.h>
- #include "GXToPostScript.h"
- #include "IOUtilities.h"
- #include "RDUtil.h"
- #include "FontHandler.h"
- #include "PublicPostScriptIE.h"
- #include "private.h"
- #include "PSIEResources.h"
- #include "GXErrors.h"
- #include "ShapeUtilities.h"
-
- #ifdef resumeLabel
- #undef resumeLabel
- #endif
- #define resumeLabel(exception)
-
-
- /**********************************
-
- Routine: OutputScreenParams:
-
- Routine puts the angle, frequency and spot function
- for a halftone record on the stack.
-
- ***********************************/
- OSErr OutputScreenParams(TRDParams* pRDParams, gxHalftone* pHalftone);
- OSErr OutputScreenParams(TRDParams* pRDParams, gxHalftone* pHalftone)
- {
- OSErr status;
- unsigned char *spotFname;
-
- switch(pHalftone->method) {
-
- case gxRoundDot:
- spotFname = "\p/RoundDotFunction";
- break;
-
- case gxSpiralDot:
- spotFname = "\p/SpiralDotFunction";
- break;
-
- case gxLineDot:
- spotFname = "\p/LineDotFunction";
- break;
-
- case gxEllipticDot:
- spotFname = "\p/EllipticDotFunction";
- break;
-
- case gxTriangleDot:
- spotFname = "\p/TriangleDotFunction";
- break;
-
- case gxDispersedDot:
- spotFname = "\p/DispersedDotFunction";
- break;
-
- case gxSquareDot:
- spotFname = "\p/SquareDotFunction";
- break;
-
- #if DEBUGLEVEL > 0
- default:
- dprintf(notrace, "Bug, Don't know halftone method: %d", pHalftone->method);
- #endif
-
- }//end switch
-
- pRDParams->resIndex = kDoScreenParams;
- status = RDResPrintf(pRDParams, pHalftone->frequency, pHalftone->angle, spotFname);
- ncheck(status);
-
- return(status);
-
- }//OutputScreenParams
-
-
- //<FF>
- /******************************************
-
- Routine DoSetScreen:
-
- Routine sets the current halftone screen for
- a black and white device.
-
- *******************************************/
- OSErr DoSetScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* theHalftone);
- OSErr DoSetScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* theHalftone)
- {
- OSErr status;
- TIEGlobalsPtr pGlobals;
- TRDParams* pRDParams;
-
- pGlobals = *hIEGlobals;
- pRDParams = pGlobals->pRDParams;
-
- nrequire(status = OutputScreenParams(pRDParams, theHalftone), failed_Screen);
-
- pRDParams->resIndex = kSetHalftone;
- nrequire(status = RDResPrintf(pRDParams, 1), failed_Screen);
-
- failed_Screen:
- return(status);
-
- }//DoSetScreen
-
- /******************************************
-
- Routine DoSetColorScreen:
-
- Routine sets the current halftone screen for
- a color device.
-
- *******************************************/
- OSErr DoSetColorScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* cHalftone, gxHalftone* mHalftone, gxHalftone* yHalftone, gxHalftone* kHalftone);
- OSErr DoSetColorScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* cHalftone, gxHalftone* mHalftone, gxHalftone* yHalftone, gxHalftone* kHalftone)
- {
- OSErr status;
- TIEGlobalsPtr pGlobals;
- TRDParams* pRDParams;
-
- pGlobals = *hIEGlobals;
- pRDParams = pGlobals->pRDParams;
-
- nrequire(status = OutputScreenParams(pRDParams, cHalftone), failed_Screen);
- nrequire(status = OutputScreenParams(pRDParams, mHalftone), failed_Screen);
- nrequire(status = OutputScreenParams(pRDParams, yHalftone), failed_Screen);
- nrequire(status = OutputScreenParams(pRDParams, kHalftone), failed_Screen);
-
- pRDParams->resIndex = kSetHalftone;
- nrequire(status = RDResPrintf(pRDParams, 4), failed_Screen);
-
- failed_Screen:
- return(status);
-
- }//DoSetScreen
-
- //<FF>
- /******************************************
-
- Routine HalftonePrimitive:
-
- Routine sets the current screen on the PostScript
- device based upone the halftone information provided.
-
- It picks the best halftone or set of halftone records
- from the provided list depending upon the device's
- color space.
-
- *******************************************/
- OSErr _HalftonePrimitive(TIEGlobalsHdl hIEGlobals, gxFormatHalftoneInfo *halftoneInfo)
- {
- OSErr status;
- gxColorSpace devCspace;
- long i;
- gxHalftone* pHalftone; // pointer into array.
-
- /** Determine whether or not to use color or monochrome screens **/
-
- devCspace = (*hIEGlobals)->params.devCSpace;
-
- if (devCspace == gxGraySpace) {
-
- /****
- find the halftone record to use, either the luminanceTint if it is there,
- or the fromBlack, else just the first one in the record.
- **/
- gxHalftone* pGrayHalftone = nil;
-
- pHalftone = halftoneInfo->halftones;
-
- for (i = halftoneInfo->numHalftones -1 ; i >= 0; --i) {
-
- if (pHalftone->tinting == gxLuminanceTint) {
-
- pGrayHalftone = pHalftone;
- break; // look no further
-
- } else if (pHalftone->tinting == gxComponent4Tint) { // we may have to use the black
-
- pGrayHalftone = pHalftone; // but keep looking.
-
- }//end if
-
- ++pHalftone;
-
- }//end for
-
- if (pGrayHalftone == nil)
- pGrayHalftone = halftoneInfo->halftones; // if we couldn't find anything just use first.
-
- nrequire(status = DoSetScreen(hIEGlobals, pGrayHalftone), failed_GrayHalftone);
-
-
- } else {
-
- /** Find the four halftone records to use **/
- gxHalftone* pCyanHalftone = nil;
- gxHalftone* pMagentaHalftone = nil;
- gxHalftone* pYellowHalftone = nil;
- gxHalftone* pBlackHalftone = nil;
-
- pHalftone = halftoneInfo->halftones;
-
- for (i = halftoneInfo->numHalftones -1 ; i >= 0; --i) {
-
- if (pHalftone->tinting == gxComponent1Tint)
- pCyanHalftone = pHalftone;
-
- else if (pHalftone->tinting == gxComponent2Tint)
- pMagentaHalftone = pHalftone;
-
- else if (pHalftone->tinting == gxComponent3Tint)
- pYellowHalftone = pHalftone;
-
- else if (pHalftone->tinting == gxComponent4Tint)
- pBlackHalftone = pHalftone;
-
- else if ((pHalftone->tinting == gxLuminanceTint) && (pBlackHalftone == nil) )
- pBlackHalftone = pHalftone;
-
- ++pHalftone;
-
- }//end for
-
- if (pBlackHalftone == nil)
- pBlackHalftone = halftoneInfo->halftones; // just use first, if there was no black.
-
- /** Use the black record for any not found **/
-
- if (pCyanHalftone == nil)
- pCyanHalftone = pBlackHalftone;
-
- if (pMagentaHalftone == nil)
- pMagentaHalftone = pBlackHalftone;
-
- if (pYellowHalftone == nil)
- pYellowHalftone = pBlackHalftone;
-
- status = DoSetColorScreen(hIEGlobals, pCyanHalftone, pMagentaHalftone,
- pYellowHalftone, pBlackHalftone);
-
- nrequire(status, failed_ColorHalftone);
-
- }//end if
-
- failed_ColorHalftone:
- failed_GrayHalftone:
-
- return(status);
-
- }//HalftonePrimitive
-
-